/**
 * 
 */
package com.rangers.auth.sample.jpa.ctrl;

import java.util.List;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.rangers.auth.base.service.RoleService;
import com.rangers.auth.sample.jpa.entity.Role;
import com.rangers.auth.sample.jpa.repo.RoleRepo;

/**
 * 角色ctrl
 * @version 1.0
 * @author fuhw
 * @date 2017年8月21日 上午10:01:59
 */
@RestController
@RequestMapping("/roles")
public class RoleCtrl {
	private final RoleService<Role, Long, RoleRepo> roleService;

	@Autowired
	public RoleCtrl(RoleService<Role, Long, RoleRepo> roleService) {
		super();
		this.roleService = roleService;
	}
	
	@GetMapping("/{id}")
	public Role get(@PathVariable("id") Long id) {
		return roleService.get(id);
	}
	
	@GetMapping
	public List<Role> list() {
		return roleService.list();
	}

	@PostMapping
	public Role post(@Valid @RequestBody Role t) {
		return roleService.create(t);
	}

	@PutMapping
	public Role put(@Valid @RequestBody Role t) {
		return roleService.update(t);
	}

	@DeleteMapping("/{id}")
	public void delete(@PathVariable("id") Long id) {
		roleService.delete(id);
	}
}
